package com.ez.supervise.dao.impl;

import java.util.List;
import java.util.Map;

import com.ez.supervise.dao.PermissionDao;
import com.ez.supervise.dao.base.BaseDaoImpl;
import com.ez.supervise.model.sys.Permission;

@SuppressWarnings("unchecked")
public class PermissionDaoImpl extends BaseDaoImpl implements PermissionDao {

    public void insert(Object permission) {
	sqlMapClientTemplate.insert("sys.insertPermission", permission);
    }

    public Object get(Long id) {
	return (Permission) sqlMapClientTemplate.queryForObject("sys.getPermissionById", id);
    }

    public void update(Object permission) {
	sqlMapClientTemplate.update("sys.updatePermission", permission);
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.ez.supervise.dao.PermissionDao#findAll()
     */
    public List findAll() {
	return (List<Permission>) sqlMapClientTemplate.queryForList("sys.findAllPermission");
    }

    /* (non-Javadoc)
     * @see com.ez.supervise.dao.PermissionDao#findAllMenu()
     */
    public Map<String, Permission> findAllMenu() {
	return sqlMapClientTemplate.queryForMap("sys.findByType","main_menu", "resId");
    }

    /* (non-Javadoc)
     * @see com.ez.supervise.dao.PermissionDao#findAllSubMenu()
     */
    public Map<String, Permission> findAllSubMenu() {
	return  sqlMapClientTemplate.queryForMap("sys.findByType","sub_menu", "resId");
    }

    /* (non-Javadoc)
     * @see com.ez.supervise.dao.PermissionDao#findPermission(java.lang.Long)
     */
    public List<Permission> findPermission(Long userId) {
	return  sqlMapClientTemplate.queryForList("sys.findPermissionByUserId",userId);
    }

}
